using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;

namespace Extractor
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            CustomExceptionHandler customExcHandler = new CustomExceptionHandler();
            Application.ThreadException += new ThreadExceptionEventHandler(customExcHandler.OnThreadException);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Extractor());
        }

        /// <summary>
        /// Custom ExceptionHandler to bypass the Native
        /// </summary>
        internal class CustomExceptionHandler
        {
            public void OnThreadException(object sender, ThreadExceptionEventArgs t)
            {
                try
                {
                    throw t.Exception;
                }

                //if an exception is thrown and the message startes with WindowsBase, it means .NET framework 3.0 isn't installed
                catch (System.IO.FileNotFoundException e)
                {
                    if (e.FileName.StartsWith("WindowsBase"))
                    {
                        MessageBox.Show("WindowsBase.dll cannot be found.  Please ensure that that the .NET Framework 3.0 is installed.");
                    }
                    else
                    {
                        throw e;
                    }
                }

                //Let the user know that we've hit an exception we didn't expect.  We show them the error message to let them know in case they can solve the problem
                catch (System.Exception e)
                {
                    MessageBox.Show("The Extractor has hit an unexpected error, it is recommended that you restart the Extractor and solve the issue before re-trying.\n\n Error hit: " + e.Message);
                }
            }
        } 
    }

}